package com.atguigu.bigdata.sparkSql


import org.apache.spark.SparkConf
import org.apache.spark.sql.{DataFrame, SparkSession}


object  SparkSQL01_Demo {
  def main(args: Array[String]): Unit = {
    //sparkConf
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("SparkSQL01")
    //sparkSession
//    val session:SparkSession = new SparkSession(sparkConf)
    val session = SparkSession.builder().config(sparkConf).getOrCreate()
    //读取数据构建DataFrame

    val frame:DataFrame = session.read.json("in/name.json")
//  展示数据
//    将dataframe转换为一张表
    frame.createOrReplaceTempView("user")
//    采用sql的语法访问数据
    session.sql("select * from user").show()

//    frame.show()

    //释放资源
    session.stop
  }

}
